#!/usr/bin/env coffee

import {Client} from 'nkn-sdk'
import CONFIG from '../lib/config'

NKN_CLIENTS = CONFIG["nkn/clients"] 6

export default (seed, ip)=>
  client = new Client {
    seed
    encrypt:false
    numSubClients:NKN_CLIENTS
    rpcServerAddr:"http://#{ip}"
  }

  client.send1 = (dest, data, options = {})->
    readyClientID = @readyClientIDs()
    length = readyClientID
    if length > 1
      n = parseInt(Math.random() * length)
    else
      n = 0

    @sendWithClient(readyClientID[n], dest, data, options)

  client


